package com.qianfeng.smartdevices.controller;

import com.qianfeng.smartdevices.annotations.AopLogAnnotation;
import com.qianfeng.smartdevices.dto.R;
import com.qianfeng.smartdevices.mapper.RoleMapper;
import com.qianfeng.smartdevices.pojo.Role;
import com.qianfeng.smartdevices.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/roles")
public class RoleController {

    private RoleMapper roleMapper;
    private RoleService roleService;
    @Autowired
    public void setRoleService(RoleService roleService) {
        this.roleService = roleService;
    }

    @Autowired
    public void setRoleMapper(RoleMapper roleMapper) {
        this.roleMapper = roleMapper;
    }

    @GetMapping("/roles")
    @AopLogAnnotation("角色查询")
    public R findAllRole(){
        List<Role> allRole = roleService.findAllRole();
        return R.setOK(allRole);
    }
    @PostMapping("/roles")
    @AopLogAnnotation("角色添加")
    public R addRole(@RequestBody Role role){
        roleService.addRole(role);
        return R.setOK();
    }
    @PutMapping("/roles")
    @AopLogAnnotation("角色更新")
    public R updateRole(@RequestBody Role role) {
        roleService.updateRole(role);
        return R.setOK();
    }
    @DeleteMapping("/roles")
    @AopLogAnnotation("角色更新")
    public R deleteRole(Long[] ids) {
        roleService.deleteRole(ids);
        return R.setOK();
    }
}
